package mygang.security.authentication;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import mygang.helper.JsonHelper;
import mygang.model.CustomResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

/**
 *
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 * date: 07/08/2012
 */
public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler {

    public CustomAuthenticationFailureHandler(){}

    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException ae) throws ServletException, IOException {
        CustomResponse result = new CustomResponse(
                CustomResponse.Result.FAILURE, 
                "error?code=AuthenticationFailure", 
                "Your login or password is incorrect!", 
                "Authentication failed");
        
        JsonHelper.prepareJsonResponse(result, response);
    }
}